package cz.mtq.mgsc.model;

/**
 * 
 * <a href="http://minigolfscorecard.googlecode.com/">MiniGolf Scorecard</a>
 * 
 * @author Miroslav Tichý
 *
 */
public class Player {

	public static final byte NUMBER_OF_HOLES = 18;
	public static final byte MAX_STROKES = 7;

	private String name;

	private byte[] holes = new byte[NUMBER_OF_HOLES];

	public Player(String name) {
		super();
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public byte getHole(int index) {
		return holes[index];
	}

	public boolean isHoleSet(int index) {
		return getHole(index) > 0;
	}

	public void setHole(int index, byte value) {
		if (value > 0 && value <= MAX_STROKES) {
			holes[index] = value;
		}
	}

	public void addOneToHole(int index) {
		byte val = getHole(index);
		if (val < MAX_STROKES) {
			setHole(index, ++val);
		}
	}

	public byte getSum() {
		byte sum = 0;
		for (byte i = 0; i < holes.length; i++) {
			sum += holes[i];
		}
		return sum;
	}

}
